package com.example.xm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.xm.entity.Timu;
import com.example.xm.service.ITimuService;
import com.example.xm.web.Result;
import com.github.pagehelper.PageInfo;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/system/timu")
public class TimuController
{
    @Autowired
    private ITimuService timuService;


    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public Result list(Timu timu)
    {
        List<Timu> list = timuService.selectTimuList(timu);
        return Result.success(list);
    }
    @GetMapping("/listt")
    public Result listt(Timu timu,Integer page,Integer size)
    {
        PageInfo<Timu> list = timuService.selectTimuListt(timu,page,size);
        return Result.success(list);
    }
    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return Result.success(timuService.selectTimuById(id));
    }

    @PostMapping("/add")
    public Result add(@RequestBody Timu timu)
    {
        return Result.success(timuService.insertTimu(timu));
    }
    @PostMapping("/edit")
    @PutMapping
    public Result edit(@RequestBody Timu timu)
    {
        return Result.success(timuService.updateTimu(timu));
    }

	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return Result.success(timuService.deleteTimuByIds(ids));
    }
    @DeleteMapping("/delete/{ids}")
    public Result delete(@PathVariable String ids){
        String[] split = ids.split(",");
        int[] intArray = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            intArray[i] = Integer.parseInt(split[i]);
        }
        timuService.delete(intArray);
        return Result.success();
    }
}
